package dreampack.dataType;

import java.sql.*;
import java.util.Calendar;

import dreampack.*;
import dreampack.dataQuery.*;

public class EmailType {
	private int emailId;
	private String emailTitle;
	private String emailAdjunct;
	private String emailContent;
	private UserType fromUser;
	private UserType toUser;
	private Timestamp createAt;
	private boolean sendFlag;
	private Timestamp readTime;
	private boolean deleteFlag;
	
	public EmailType() { }
	
	public boolean init(DreamDB dreamDb, ResultSet rs) throws Exception {
		boolean bRet = true;
		
		this.emailId = (int)rs.getInt("id");
		this.emailTitle = (String)rs.getString("title");
		this.emailAdjunct = (String)rs.getString("adjunct");
		this.emailContent = (String)rs.getString("content");
		this.fromUser = (UserType)UserQuery.queryById(dreamDb, rs.getInt("from_id"));
		this.toUser = (UserType)UserQuery.queryById(dreamDb, rs.getInt("to_id"));
		this.createAt = (Timestamp)rs.getTimestamp("create_at");
		this.sendFlag = (boolean)rs.getBoolean("send_flag");
		this.readTime = (Timestamp)rs.getTimestamp("read_time");
		this.deleteFlag = (boolean)rs.getBoolean("delete_flag");
		
		return bRet;
	}
	public int getId(){
		return this.emailId;
	}
	public String getTitle(){
		return this.emailTitle;
	}
	public String getAdjunct(){
		return this.emailAdjunct;
	}
	public String getContent(){
		return this.emailContent;
	}
	public UserType getSendUser(){
		return this.fromUser;
	}
	public UserType getReceiveUser(){
		return this.toUser;
	}
	public java.util.Date getSendTime(){
		java.util.Date tempDate = null;
		if (null != this.createAt) {
			Calendar cal = Calendar.getInstance();
			cal.setTimeInMillis(this.createAt.getTime());
			tempDate = cal.getTime();
		}
		return tempDate;
	}
	public boolean getSendFlag(){
		return this.sendFlag;
	}
	public java.util.Date getReadTime(){
		java.util.Date tempDate = null;
		if (null != this.readTime) {
			Calendar cal = Calendar.getInstance();
			cal.setTimeInMillis(this.readTime.getTime());
			tempDate = cal.getTime();
		}
		return tempDate;
	}
	public boolean getDeleteFlag(){
		return this.deleteFlag;
	}
}
